package com.jian.safecopyonwritearraylist;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author Jiange
 * @create 2021-07-16-10:58
 */
public class CopyOnWriteArrayListShow {
    public static void main(String[] args) {
        //写时复制技术  并发读、独立写 所有人都能读 写的时候上锁lock先开创一个一样的list然后往新的list里面写 最后合并旧的
       List<String> strings = new CopyOnWriteArrayList<>();

        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                for (int j = 0; j < 10; j++) {
                    strings.add(UUID.randomUUID().toString().substring(0,8));
                    System.out.println(strings);
                }
            },String.valueOf(i)).start();
        }
    }
}
